Executable documents

Quarto

Aud H. Halbritter

The problem

Doing science

Lack of reproducibility

Executable documents

Quarto lets you have code and text in the same document.

If you change or update the data, code, or results, new figures, tables and text are automatically generated in the document.

Credit: Allison Horst

Elements of a quarto file

YAML

The YAML is metadata for the document that goes right at the top of the file between two sets of three dashes.

---
title: "My Manuscript"
format: html
date: 2022-04-03
---
  • key:value pairs
  • author, title, date
  • sensitive to white space

Output formats

Quarto documents can be rendered in about 40 formats! Html, word and pdf are very common.

Producing an html file to view in a browser is the simplest, as no extra software needs installing.

---
title: "My Manuscript"
format: html
---

Text - source vs visual editor

Text - syntax

Markdown Syntax Output
# Header 1

Header 1

## Header 2

Header 2

*italics* and **bold** italics and bold
superscript m^2^ superscript m2
subscript CO~2~ subscript CO2

Code blocks

Code in a quarto document is contained in code blocks.

This is a code block that reads in a trait dataset from Svalbard.

```{r}
#| label: data-import
#| message: false
traits <- read_delim(
    file = "data/PFTC4_Svalbard_2018_ITEX_Traits.csv") 
```

Inline code

In addition to the output from code blocks, you can insert code directly into text. This lets you avoid copying and pasting numbers from the output.

Inline code is enclosed by back-ticks and starts with an r.

Seven times six is `r 7 * 6`

In the output this would look like:

Seven times six is 42

Exercise

Go to the BioStats book on reproducible documents

And work through chapter 1-4.

If you want more, have a look at the quarto book